{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5a936e50",
   "metadata": {},
   "source": [
    "## 作业\n",
    "#### 尝试使用百度API图像识别其中一个做用户需求分析并设计一个最小可行性应用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a494075",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "818064e5",
   "metadata": {},
   "source": [
    "## （1）产品需求文档——小酌一杯"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a87014dc",
   "metadata": {},
   "source": [
    "|产品名称|“小酌一杯”|\n",
    "|---|---|\n",
    "|产品描述|一款可以识别红酒酒标，返回红酒的国家、酒品描述等相关信息，且可以跳转到百度搜索的小程序|\n",
    "|产品类型|小程序|\n",
    "|产品作者|小邱同学|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32dab46c",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74a6f6be",
   "metadata": {},
   "source": [
    "## （2）价值主张画布\n",
    "* 用户痛点：不清楚酒的名字、品种、酒庄等相关信息，记不住全名去百度搜索相关信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6a2a04c",
   "metadata": {},
   "source": [
    "* 场景：想要在家小酌一杯的男士女士、用于进货的厂商、酒类电商、红酒展销等"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e526e8b9",
   "metadata": {},
   "source": [
    "* 目标用户：在家小酌一杯的男士女士、厂商、电商等"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7aba8006",
   "metadata": {},
   "source": [
    "* 产品功能：在红酒消费越来越趋平民化的今天，红酒消费也越来越多，了解一些红酒知识还是有好处的。不过大家现在对红酒还都不是十分的了解，想要根据掌握的红酒知识，直接说出眼前的红酒的名称国家、产区、特点等信息，还是具有一定的困难的。“小酌一杯”小程序，只需要简单拍张照，便可直接反馈给你眼前的红酒信息，满足用户需求。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5651bcb",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "830f7ece",
   "metadata": {},
   "source": [
    "## （3）各平台API对比\n",
    "|  |百度AI开发者平台 | 京东人工智能开放平台|\n",
    "|------|---------------|-------------------|\n",
    "|API|“红酒识别”|“酒标识别”|\n",
    "|功能对比|输入的一张图片，输出图片中的红酒名称、国家、产区、酒庄、类型、糖分、葡萄品种、酒品描述等信息。|发送图片二进制数据，直接返回葡萄酒识别结果信息。|\n",
    "|价格对比|免费试用|免费试用|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77ac7252",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "010d9311",
   "metadata": {},
   "source": [
    "## （4）竞品分析\n",
    "\n",
    "> AI识美酒（小程序）   \n",
    ">> * 功能：AI智能识别红酒信息（红酒名称，国家，产区，子产区，酒庄，酒类型，糖分类型，色泽，葡萄品种，品尝温度，酒品描述等）\n",
    ">> * 优点：功能较齐全、出现时间较早\n",
    ">> * 缺点：识别结果信息较少\n",
    "\n",
    "> “小酌一杯”（小程序）\n",
    ">> * 功能：识别结果增加更丰富的信息，包括：红酒的国家、产区、酒庄、类型、糖分、色泽、葡萄品种、品尝温度、酒品描述等。配合手机APP拍摄可以提供详细的红酒介绍，同时可结合识别结果进一步为用户提供商品推荐、营养搭配等服务。\n",
    ">> * 优点：识别信息较为丰富，界面简洁、易操作、处理图片速度快、可跳转百度搜索\n",
    ">> * 缺点：功能较少、知名度低、市场竞争力弱"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37c77310",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d3e3938",
   "metadata": {},
   "source": [
    "## （5）用户可欲性 （DFV 模型）\n",
    "###  1）用户可欲性 Desirability\n",
    "* 小程序使用方法简单，用户只需上传/拍摄图片文件，小程序便调用API对用户图片内容进行自动识别。用户无需过多操作即可了解红酒相关信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8ae6621",
   "metadata": {},
   "source": [
    "### 2）技术可行性 Feasibility\n",
    "* 着眼于用户对查询结果效率的需求，调用红酒识别的API服务，在极快的时间内放回相关结果。人工智能API的能力优异，识别准确率均在九成多以上，能够很好地服务用户。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21f0fe5a",
   "metadata": {},
   "source": [
    "### 3）商业可行性 Viability\n",
    "* 百度AI开发平台提供了一定数量的免费API调用额度和优惠的额度套餐服务支持我们的产品技术运行，而且成本低廉。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e249aba",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "873c8249",
   "metadata": {},
   "source": [
    "## （6）需求列表\n",
    "|用户需求|\t智能加值|\t使用API|\t优先级|\n",
    "|--------|----|----|----|\n",
    "|想知道红酒国家、产区、酒庄、类型|\t通过自然语言处理对文章进行内容识别与分类|\t红酒识别API|\t一（最重要）|\n",
    "|想对红酒名称进行百度搜索|\t通过查看更多直接跳转搜索结果页面|\t无\t|二（次重要）|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0768e8c7",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fc7ee41",
   "metadata": {},
   "source": [
    "## （7）产品结构图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbb3094e",
   "metadata": {},
   "source": [
    "![产品结构图](./y.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2621cde",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1da2b1c5",
   "metadata": {},
   "source": [
    "## （8）产品原型图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "350e3dab",
   "metadata": {},
   "source": [
    "![产品结构图](./q.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c44a1c9",
   "metadata": {},
   "source": [
    "![产品结构图](./r.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae7aaff0",
   "metadata": {},
   "source": [
    "![产品结构图](./t.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ffa97d1",
   "metadata": {},
   "source": [
    "![产品结构图](./w.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68060ab4",
   "metadata": {},
   "source": [
    "![产品结构图](./e.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c1faa74",
   "metadata": {},
   "source": [
    "## （9）实现代码 API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8886a338",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.44c8043cfd3cf7a787de14e1d7f5da55.315360000.1964436683.282335-25863386', 'expires_in': 2592000, 'session_key': '9mzdWBIm8naPSG2f7KEWj2SCzhuHOOFPoGF+5bmCvHHj0UDgMCaFp1bbRhIrqxfvIl4R/SWo7UykSAUIJf4H9VAUIbeDqQ==', 'access_token': '24.cb014aec7df9f1c668cb2a535c9338c8.2592000.1651668683.282335-25863386', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': 'cec93deed2d08bfa4e9b7535f5c55273'}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token'\n",
    "\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'6wESwZxKqy83cWrYg0EIKRgx',\n",
    "    'client_secret':'lOBHtua8XnGAZly2ncd35MxQsPXk7yI9'\n",
    "}\n",
    "\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b3c9a6e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.cb014aec7df9f1c668cb2a535c9338c8.2592000.1651668683.282335-25863386'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xiaoqiu_AI = response.json()['access_token']\n",
    "xiaoqiu_AI"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31db04ee",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c2b77206",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'countryEn': 'France', 'grapeEn': '', 'grapeCn': '', 'color': '深紫红色/Dark Violet', 'regionCn': '波尔多', 'regionEn': 'Bordeaux', 'subRegionEn': 'Medoc', 'description': '该酒拥有木香和辛料香，口中结构感强且非常平衡，强劲感逐渐增强，异常优雅，尾香悠长，以红色成熟水果的香气为主。', 'subRegionCn': '梅多克', 'classifyByColor': '红葡萄酒/Red Wine', 'wineryEn': 'Chateau Lafite Rothschild', 'wineryCn': '拉菲古堡', 'classifyBySugar': '干型/Dry', 'wineNameEn': 'Chateau Lafite Rothschild', 'wineNameCn': '拉菲古堡红葡萄酒（正牌）', 'tasteTemperature': '18-22℃', 'hasdetail': 1, 'countryCn': '法国'}, 'log_id': 1510963265919007083}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别—红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('13.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "payload={\n",
    "    'access_token':xiaoqiu_AI,\n",
    "    'image':img\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c17be31e",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "233e89e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'countryEn': 'Chile', 'grapeEn': '', 'grapeCn': '', 'color': '深紫红色/Dark Violet', 'regionCn': '中央谷地', 'regionEn': 'Central Valley', 'subRegionEn': 'Colchagua Valley', 'description': '此酒呈深紫红色，散发黑果风味及带点凉爽地区马齐古的凯奈尔的辛辣轻快果香，亦有小味儿多的强烈黑浆果味的香气，酒体丰厚，大量成熟的单宁赋予收敛感并令酒体结构更佳。', 'subRegionCn': '空加瓜谷', 'classifyByColor': '红葡萄酒/Red Wine', 'wineryEn': 'Montes Wines', 'wineryCn': '蒙特斯酒庄', 'classifyBySugar': '干型/Dry', 'wineNameEn': 'Montes Purple Angel', 'wineNameCn': '蒙特斯紫天使红葡萄酒', 'tasteTemperature': '14-18℃', 'hasdetail': 1, 'countryCn': '智利'}, 'log_id': 1510963279644068648}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别—红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('11.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "payload={\n",
    "    'access_token':xiaoqiu_AI,\n",
    "    'image':img\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2ead5f7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'result': {'countryEn': 'Chile',\n",
       "  'grapeEn': '',\n",
       "  'grapeCn': '',\n",
       "  'color': '深紫红色/Dark Violet',\n",
       "  'regionCn': '中央谷地',\n",
       "  'regionEn': 'Central Valley',\n",
       "  'subRegionEn': 'Colchagua Valley',\n",
       "  'description': '此酒呈深紫红色，散发黑果风味及带点凉爽地区马齐古的凯奈尔的辛辣轻快果香，亦有小味儿多的强烈黑浆果味的香气，酒体丰厚，大量成熟的单宁赋予收敛感并令酒体结构更佳。',\n",
       "  'subRegionCn': '空加瓜谷',\n",
       "  'classifyByColor': '红葡萄酒/Red Wine',\n",
       "  'wineryEn': 'Montes Wines',\n",
       "  'wineryCn': '蒙特斯酒庄',\n",
       "  'classifyBySugar': '干型/Dry',\n",
       "  'wineNameEn': 'Montes Purple Angel',\n",
       "  'wineNameCn': '蒙特斯紫天使红葡萄酒',\n",
       "  'tasteTemperature': '14-18℃',\n",
       "  'hasdetail': 1,\n",
       "  'countryCn': '智利'},\n",
       " 'log_id': 1510963279644068648}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d59a9fcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "jiu = response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "73a466f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "hongjiu = jiu['result']['wineNameCn']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7a256579",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 跳转百度搜索\n",
    "from os import system\n",
    "search = hongjiu\n",
    "interface = 'http://www.baidu.com/s?wd='\n",
    "system('start iexplore \"{0}\"'.format(interface + search))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84647722",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09e1cfb0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
